package com.sxm.yiwei.pinche;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.squareup.picasso.Picasso;
import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.AppManager;
import com.sxm.yiwei.activitis.FWHiteMeShopActivity;
import com.sxm.yiwei.base.BaseActivity;
import com.sxm.yiwei.beans.pinche.Order;
import com.sxm.yiwei.constant.Common;
import com.sxm.yiwei.constant.Constant;
import com.sxm.yiwei.tools.BookPayActivity;
import com.sxm.yiwei.tools.CallPhone;
import com.sxm.yiwei.tools.CircleTransform;
import com.sxm.yiwei.utils.DateUtil;
import com.sxm.yiwei.views.CircleImage;

import org.xutils.x;

import java.util.ArrayList;

public class PincheOrderDetailHostActivity extends BaseActivity {
    private RelativeLayout rl_back;
    private TextView tv_title,departTime,startPos,endPos,outStyle,orderType,distance,phone,words,orderCode,orderTime
            ,wp_total_price,wp_loss,wp_seats_need,wp_nickname,wp_recent_come,wp_wei,wp_need_loss,wt_rest_seats
            ,wt_price,wt_seats_support,wt_total_price,wt_loss,wt_pay_detail,wt_pay_time,ws_seats_need,ws_total_price
            ,ws_loss,ws_nickname,ws_recent_come,ws_wei,ws_pay_type,ws_pay_time,is_seats_need,is_total_price,is_nickname
            ,is_recent_come,is_wei,is_pay_type,is_pay_time,is_phone_click,wf_vehicle_type,wf_seats_need,wf_total_price
            ,wf_nickname,wf_recent_come,wf_wei,wf_phone_click,wf_pay_type,wf_pay_time,f_seats_need,f_total_price,f_nickname
            ,f_recent_come,f_wei,f_phone_click,f_pay_type,f_pay_time,l_title_info,l_total_price,l_loss,l_seats_need
            ,l_pay_type,l_pay_time,e_loss,e_total_price,e_seats_support,e_pay_type,e_pay_time;
    private ImageView ws_img1,ws_img2,ws_img3,ws_img4,is_img1,is_img2,is_img3,is_img4,wf_img1
            ,wf_img2,wf_img3,wf_img4,f_img1,f_img2,f_img3,f_img4,l_img4,l_img3,l_img2,l_img1,l_whoPay
            ,e_img1,e_img2,e_img3,e_img4;
    private CircleImage wp_icon,ws_icon,is_icon,wf_icon,f_icon;
    private Button wp_button1;
    private Button wp_button2;
    private Button wt_button1;
    private Button wt_button2;
    private Button ws_ticket_refund;
    private Button ws_start_service;
    private Button is_appeal;
    private Button is_finish;
    private Button wf_appeal;
    private Button wf_finish;
    private Button f_appeal;
    private Button f_finish;
    private Button e_cancel_appeal;

    private int identity;
    private int order_type;
    private int go_type;
    private Order order;
    private TextView wp_price;
    private LinearLayout wp_ll_price;
    private TextView wp_text;
    private TextView wp_phone_intro;
    private View wp_line;
    private LinearLayout wp_title_info;
    private TextView ws_phone_click;
    private TextView text_phone;
    private TextView text_words;
    private TextView l_text1;
    private TextView l_text2;
    private TextView e_text1;
    private TextView e_text2;
    private LinearLayout e_ll_depart_time;
    private LinearLayout e_ll_go_result;
    private TextView wp_text1;
    private TextView wp_text2;
    private LinearLayout wp_ll_images;
    private TextView wt_text1;
    private ImageView[] ws_cars={ws_img1,ws_img2,ws_img3,ws_img4};
    private ImageView[] is_cars={is_img1,is_img2,is_img3,is_img4};
    private int position;
    private String orderId;
    private String serviceId;

    @Override
    public void setContentView() {
        order_type = getIntent().getIntExtra("order_type",-1);
        go_type = getIntent().getIntExtra("go_type",-1);
        position = getIntent().getIntExtra("position",-1);
        order = (Order) getIntent().getSerializableExtra("order");
        orderId = getIntent().getStringExtra("order_id");
        serviceId = getIntent().getStringExtra("serviceId");
        switch (order_type){
            case Constant.WAIT_PAY:
                setContentView(R.layout.podh_wait_pay);
                break;
            case Constant.WAIT_TAKE:
                setContentView(R.layout.podh_wait_take);
                break;
            case Constant.WAIT_SURVICE:
                setContentView(R.layout.podh_wait_survice);
                break;
            case Constant.IN_SURVICE:
                setContentView(R.layout.podh_in_survice);
                break;
            case Constant.WAIT_FINISH:
                setContentView(R.layout.podh_wait_finish);
                break;
            case Constant.FINISHED:
                setContentView(R.layout.podh_finished);
                break;
            case Constant.LOSS:
                setContentView(R.layout.podh_loss);
                break;
            case Constant.EXCEPTION:
                setContentView(R.layout.podh_exception);
                break;
        }
    }

    @Override
    public void initView() {
        rl_back = (RelativeLayout)findViewById(R.id.rl_back);
        tv_title = (TextView)findViewById(R.id.tv_title);
        outStyle = (TextView)findViewById(R.id.tv_style);
        orderType = (TextView)findViewById(R.id.tv_order_type);
        distance = (TextView)findViewById(R.id.tv_distance);
        departTime = (TextView)findViewById(R.id.tv_depart_time);
        startPos = (TextView)findViewById(R.id.tv_start_pos);
        endPos = (TextView)findViewById(R.id.tv_end_pos);
        phone = (TextView)findViewById(R.id.tv_phone);
        words = (TextView)findViewById(R.id.tv_words);
        orderCode = (TextView)findViewById(R.id.tv_order_code);
        orderTime = (TextView)findViewById(R.id.tv_start_time);
        text_phone = (TextView)findViewById(R.id.text_phone);
        text_words = (TextView)findViewById(R.id.text_words);
        switch (order_type){
            case Constant.WAIT_PAY:
                wp_total_price = (TextView)findViewById(R.id.tv_total_price);
                wp_loss = (TextView)findViewById(R.id.tv_loss);
                wp_seats_need = (TextView)findViewById(R.id.tv_seats_need);

                wp_icon = (CircleImage) findViewById(R.id.iv_icon);
                wp_nickname = (TextView)findViewById(R.id.tv_nickname);
                wp_recent_come = (TextView)findViewById(R.id.tv_recent_come);
                wp_wei = (TextView)findViewById(R.id.tv_wei);

                wp_need_loss = (TextView)findViewById(R.id.tv_need_loss);
                wp_button1 = (Button)findViewById(R.id.button1);
                wp_button2 = (Button)findViewById(R.id.button2);

                wp_price = (TextView)findViewById(R.id.tv_price);
                wp_ll_price = (LinearLayout)findViewById(R.id.ll_price);
                wp_text = (TextView)findViewById(R.id.text);

                wp_phone_intro = (TextView)findViewById(R.id.phone_intro);
                wp_line = findViewById(R.id.line);
                wp_title_info = (LinearLayout)findViewById(R.id.LL_title_info);

                wp_text1 = (TextView)findViewById(R.id.text1);
                wp_text2 = (TextView)findViewById(R.id.text2);
                wp_ll_images = (LinearLayout)findViewById(R.id.ll_images);

                break;
            case Constant.WAIT_TAKE:
                wt_rest_seats = (TextView)findViewById(R.id.tv_rest_seats);
                wt_price = (TextView)findViewById(R.id.tv_price);
                wt_seats_support = (TextView)findViewById(R.id.tv_seats_support);
                wt_total_price = (TextView)findViewById(R.id.tv_total_price);
                wt_loss = (TextView)findViewById(R.id.tv_loss);
                wt_pay_detail = (TextView)findViewById(R.id.tv_pay_detail);
                wt_pay_time = (TextView)findViewById(R.id.tv_pay_time);
                wt_button1 = (Button)findViewById(R.id.button1);
                wt_button2 = (Button)findViewById(R.id.button2);
                wt_text1 = (TextView)findViewById(R.id.text1);
                break;
            case Constant.WAIT_SURVICE:
                ws_seats_need = (TextView)findViewById(R.id.tv_seats_need);
                ws_total_price = (TextView)findViewById(R.id.tv_total_price);
                ws_loss = (TextView)findViewById(R.id.tv_loss);
                ws_img1 = (ImageView)findViewById(R.id.img1);
                ws_img2 = (ImageView)findViewById(R.id.img2);
                ws_img3 = (ImageView)findViewById(R.id.img3);
                ws_img4 = (ImageView)findViewById(R.id.img4);

                ws_icon = (CircleImage) findViewById(R.id.iv_icon);
                ws_nickname = (TextView)findViewById(R.id.tv_nickname);
                ws_recent_come = (TextView)findViewById(R.id.tv_recent_come);
                ws_wei = (TextView)findViewById(R.id.tv_wei);
                ws_pay_type = (TextView)findViewById(R.id.tv_pay_type);
                ws_pay_time = (TextView)findViewById(R.id.tv_pay_time);
                ws_ticket_refund = (Button)findViewById(R.id.btn_ticket_refund);
                ws_start_service = (Button)findViewById(R.id.btn_start_service);
                ws_phone_click = (TextView)findViewById(R.id.tv_phone_click);
                break;
            case Constant.IN_SURVICE:
                is_seats_need = (TextView)findViewById(R.id.tv_seats_need);
                is_total_price = (TextView)findViewById(R.id.tv_total_price);
                is_img1 = (ImageView)findViewById(R.id.img1);
                is_img2 = (ImageView)findViewById(R.id.img2);
                is_img3 = (ImageView)findViewById(R.id.img3);
                is_img4 = (ImageView)findViewById(R.id.img4);

                is_icon = (CircleImage) findViewById(R.id.iv_icon);
                is_nickname = (TextView)findViewById(R.id.tv_nickname);
                is_recent_come = (TextView)findViewById(R.id.tv_recent_come);
                is_wei = (TextView)findViewById(R.id.tv_wei);
                is_phone_click = (TextView)findViewById(R.id.tv_phone_click);
                is_pay_type = (TextView)findViewById(R.id.tv_pay_type);
                is_pay_time = (TextView)findViewById(R.id.tv_pay_time);
                is_appeal = (Button)findViewById(R.id.btn_appeal);
                is_finish = (Button)findViewById(R.id.btn_finish);
                break;
            case Constant.WAIT_FINISH:
                wf_vehicle_type = (TextView)findViewById(R.id.tv_vehicle_type);
                wf_seats_need = (TextView)findViewById(R.id.tv_seats_need);
                wf_total_price = (TextView)findViewById(R.id.tv_total_price);
                wf_img1 = (ImageView)findViewById(R.id.img1);
                wf_img2 = (ImageView)findViewById(R.id.img2);
                wf_img3 = (ImageView)findViewById(R.id.img3);
                wf_img4 = (ImageView)findViewById(R.id.img4);

                wf_icon = (CircleImage) findViewById(R.id.iv_icon);
                wf_nickname = (TextView)findViewById(R.id.tv_nickname);
                wf_recent_come = (TextView)findViewById(R.id.tv_recent_come);
                wf_wei = (TextView)findViewById(R.id.tv_wei);
                wf_phone_click = (TextView)findViewById(R.id.tv_phone_click);
                wf_pay_type = (TextView)findViewById(R.id.tv_pay_type);
                wf_pay_time = (TextView)findViewById(R.id.tv_pay_time);
                wf_appeal = (Button)findViewById(R.id.btn_appeal);
                wf_finish = (Button)findViewById(R.id.btn_finish);
                break;
            case Constant.FINISHED:
                f_seats_need = (TextView)findViewById(R.id.tv_seats_need);
                f_total_price = (TextView)findViewById(R.id.tv_total_price);
                f_img1 = (ImageView)findViewById(R.id.img1);
                f_img2 = (ImageView)findViewById(R.id.img2);
                f_img3 = (ImageView)findViewById(R.id.img3);
                f_img4 = (ImageView)findViewById(R.id.img4);

                f_icon = (CircleImage) findViewById(R.id.iv_icon);
                f_nickname = (TextView)findViewById(R.id.tv_nickname);
                f_recent_come = (TextView)findViewById(R.id.tv_recent_come);
                f_wei = (TextView)findViewById(R.id.tv_wei);
                f_phone_click = (TextView)findViewById(R.id.tv_phone_click);
                f_pay_type = (TextView)findViewById(R.id.tv_pay_type);
                f_pay_time = (TextView)findViewById(R.id.tv_pay_time);
                f_appeal = (Button)findViewById(R.id.btn_appeal);
                f_finish = (Button)findViewById(R.id.btn_release_again);
                break;
            case Constant.LOSS:
                l_title_info = (TextView)findViewById(R.id.tv_title_info);
                l_total_price = (TextView)findViewById(R.id.tv_total_price);
                l_loss = (TextView)findViewById(R.id.tv_loss);
                l_seats_need = (TextView)findViewById(R.id.tv_seats_need);

                l_img1 = (ImageView)findViewById(R.id.img1);
                l_img2 = (ImageView)findViewById(R.id.img2);
                l_img3 = (ImageView)findViewById(R.id.img3);
                l_img4 = (ImageView)findViewById(R.id.img4);
                l_pay_type = (TextView)findViewById(R.id.tv_pay_type);
                l_pay_time = (TextView)findViewById(R.id.tv_pay_time);
                l_whoPay = (ImageView)findViewById(R.id.iv_whoPay);

                l_text1 = (TextView)findViewById(R.id.text1);
                l_text2 = (TextView)findViewById(R.id.text2);
                break;
            case Constant.EXCEPTION:
                e_loss = (TextView)findViewById(R.id.tv_loss);
                e_total_price = (TextView)findViewById(R.id.tv_total_price);
                e_seats_support = (TextView)findViewById(R.id.tv_seats_support);

                e_img1 = (ImageView)findViewById(R.id.img1);
                e_img2 = (ImageView)findViewById(R.id.img2);
                e_img3 = (ImageView)findViewById(R.id.img3);
                e_img4 = (ImageView)findViewById(R.id.img4);
                e_pay_type = (TextView)findViewById(R.id.tv_pay_type);
                e_pay_time = (TextView)findViewById(R.id.tv_pay_time);
                e_cancel_appeal = (Button)findViewById(R.id.btn_cancel_appeal);
                e_text1 = (TextView)findViewById(R.id.text1);
                e_text2 = (TextView)findViewById(R.id.text2);
                e_ll_depart_time = (LinearLayout)findViewById(R.id.ll_depart_time);
                e_ll_go_result = (LinearLayout)findViewById(R.id.ll_go_result);
                break;
        }

    }

    @Override
    public void initListener() {
        rl_back.setOnClickListener(this);
        switch (order_type){
            case Constant.WAIT_PAY:
                wp_button1.setOnClickListener(this);
                wp_button2.setOnClickListener(this);
                wp_wei.setOnClickListener(this);
                break;
            case Constant.WAIT_TAKE:
                wt_button1.setOnClickListener(this);
                wt_button2.setOnClickListener(this);
                break;
            case Constant.WAIT_SURVICE:
                ws_start_service.setOnClickListener(this);
                ws_ticket_refund.setOnClickListener(this);
                ws_wei.setOnClickListener(this);
                ws_phone_click.setOnClickListener(this);
                break;
            case Constant.IN_SURVICE:
                is_appeal.setOnClickListener(this);
                is_finish.setOnClickListener(this);
                is_wei.setOnClickListener(this);
                is_phone_click.setOnClickListener(this);
                break;
            case Constant.WAIT_FINISH:
                wf_appeal.setOnClickListener(this);
                wf_finish.setOnClickListener(this);
                wf_wei.setOnClickListener(this);
                wf_phone_click.setOnClickListener(this);
                break;
            case Constant.FINISHED:
                f_appeal.setOnClickListener(this);
                f_finish.setOnClickListener(this);
                f_wei.setOnClickListener(this);
                f_phone_click.setOnClickListener(this);
                break;
            case Constant.LOSS:
                break;
            case Constant.EXCEPTION:
                e_cancel_appeal.setOnClickListener(this);
                e_ll_go_result.setOnClickListener(this);
                break;
        }
    }

    @Override
    public void initData() {
        setDataToView();
        //getOrderDetail();

    }
    /*
    * 传递数据展示详情
    * */
    private void setDataToView() {
    /*
    * 标题
    * */
        if (order_type== Constant.EXCEPTION){
            tv_title.setText("订单异常订单详情");
        }else if (order_type==Constant.FINISHED){
            if (order.getForm_way()==Constant.RELEASE){
                tv_title.setText("车票详情");
            }else {
                tv_title.setText("订单详情");
            }
        }else if (order_type==Constant.WAIT_PAY){
            if (order.getForm_way()==Constant.RELEASE){
                tv_title.setText("发布详情");
            }else {
                tv_title.setText("订单详情");
            }
        }else if (order_type==Constant.WAIT_TAKE){
            tv_title.setText("待接单详情");
        }else {
            tv_title.setText("订单详情");
        }

        //
        if (go_type==Constant.LONG){
            outStyle.setText("长途");
        }else if (go_type==Constant.CITY){
            outStyle.setText("同城");
        }else if (go_type==Constant.TRAVEL){
            outStyle.setText("旅游");
        }else {
            outStyle.setText("长途急件");
        }

        //
        if (order.getWho_created()==Constant.PASSENGER){
            text_phone.setText("乘客联系方式：");
            text_words.setText("我的留言：");
        }else {
            text_phone.setText("乘客联系方式：");
            text_words.setText("乘客留言：");
        }

        //
        distance.setText(order.getDistance()+"公里");
        departTime.setText(order.getDepart_time());
        startPos.setText(order.getStart_place());
        endPos.setText(order.getEnd_place());
        phone.setText(order.getPhone());
        if (TextUtils.isEmpty(order.getWords())){
            words.setText("没有留言");

        }else {
            words.setText(order.getWords());

        }
        orderCode.setText(order.getOrder_code());
        orderTime.setText(order.getStart_time());
        switch (order_type){
            case Constant.WAIT_PAY:
                orderType.setText("--待付款");
                if (go_type!=Constant.LONG_HURRY){
                    wp_total_price.setText(order.getTotal_money()+"元");
                    wp_loss.setText(order.getLoss_money()+"元");
                    if (tv_title.getText().toString().equals("发布详情")){
                        wp_ll_price.setVisibility(View.VISIBLE);

                        text_phone.setText("我的联系方式：");
                        wp_phone_intro.setVisibility(View.GONE);
                        text_words.setText("我的留言：");

                        wp_line.setVisibility(View.GONE);
                        wp_title_info.setVisibility(View.GONE);

                        wp_seats_need.setText("提供"+order.getSeats()+"个座位");
                        wp_price.setText(order.getSingle_money()+"元");
                        if (order.getIs_timeout()==Constant.YES){
                            wp_text.setText("已超时");
                            wp_need_loss.setText("");
                            wp_button2.setText("重新发布");

                        }else {
                            wp_text.setText("信息未发布，需支付爽约金");
                            wp_need_loss.setText(order.getLoss_money()+"元");
                            wp_button2.setText("立即发布");

                        }



                    }else {
                        wp_ll_price.setVisibility(View.GONE);
                        text_phone.setText("乘客联系方式：");
                        wp_phone_intro.setVisibility(View.VISIBLE);
                        text_words.setText("乘客留言:");
                        wp_line.setVisibility(View.VISIBLE);
                        wp_title_info.setVisibility(View.VISIBLE);
                        wp_seats_need.setText("需求"+order.getSeats()+"个座位");

                        wp_text.setText("未支付，抢单未成功，");

                        Picasso.with(this).load(Common.IMAGE_HOST+order.getIcon()).error(R.mipmap.morentouxiang).transform(new CircleTransform()).into(wp_icon);
                        if (TextUtils.isEmpty(order.getNickname())){
                            wp_nickname.setText("暂无昵称");

                        }else {
                            wp_nickname.setText(order.getNickname());

                        }
                        wp_recent_come.setText("[24h前来过]");

                        if (order.getIs_timeout()==Constant.YES){
                            wp_text.setText("已超时");
                            wp_need_loss.setText("");
                            wp_button2.setVisibility(View.GONE);
                        }else {
                            wp_text.setText("未支付，抢单未成功，需支付爽约金");
                            wp_need_loss.setText(order.getLoss_money()+"元");
                            wp_button2.setText("立即支付");
                        }

                    }
                }else {
                    if (order.getIs_timeout()==Constant.YES){
                        wp_text1.setText("运费");
                        wp_seats_need.setText("可载空间");
                        wp_text.setText("已超时，需支付");
                        wp_button2.setText("重新发布");
                        wp_line.setVisibility(View.GONE);
                        wp_title_info.setVisibility(View.GONE);
                    }else {
                        if (order.getForm_way()==Constant.RELEASE){
                            wp_text1.setText("运费");
                            wp_seats_need.setText("可载空间");
                            wp_text.setText("信息未发布，需支付");
                            wp_button2.setText("立即发布");
                            wp_line.setVisibility(View.GONE);
                            wp_title_info.setVisibility(View.GONE);
                        }else {
                            wp_ll_images.setVisibility(View.GONE);
                            wp_text1.setText("运费");
                            wp_text2.setText("保价");
                            wp_seats_need.setText("可载空间");
                            wp_text.setText("抢单未成功，需支付");
                            wp_button2.setText("立即抢单");
                        }
                    }

                }


                break;
            case Constant.WAIT_TAKE:
                orderType.setText("--待接单");
                distance.setText(order.getDistance()+"公里");
                wt_rest_seats.setText("剩余"+order.getSeats()+"个座位");
                wt_price.setText(order.getSingle_money()+"元");
                departTime.setText(order.getDepart_time());
                startPos.setText(order.getStart_place());
                endPos.setText(order.getEnd_place());
                wt_seats_support.setText(order.getSeats()+"个");
                wt_total_price.setText(order.getTotal_money()+"元");
                wt_loss.setText(order.getLoss_money()+"元");
                phone.setText(order.getPhone());
                words.setText(order.getWords());
                orderCode.setText(order.getOrder_code());
                orderTime.setText(order.getStart_time());
                wt_pay_time.setText(order.getPay_time());
                text_phone.setText("我的联系方式：");
                text_words.setText("我的留言：");

                if (order.getPay_type()==Constant.ALIPAY){
                    wt_pay_detail.setText("支付宝支付爽约金"+order.getLoss_money()+"元");
                }else if (order.getPay_type()==Constant.RESTPAY){
                    wt_pay_detail.setText("余额支付爽约金"+order.getLoss_money()+"元");
                }else {
                    wt_pay_detail.setText("微信支付爽约金"+order.getLoss_money()+"元");
                }

                if (go_type!=Constant.LONG_HURRY){
                    if (order.getIs_timeout()==Constant.YES){
                        wt_button1.setText("取消订单");
                        wt_button2.setText("再次发布");
                    }else {
                        if (order.getIs_sale_start()==Constant.YES){
                            wt_button1.setText("停止售票");
                            wt_button2.setText("取消订单");
                        }else {
                            wt_button1.setText("开始售票");
                            wt_button1.setTextColor(getResources().getColor(R.color.color_offline));
                            wt_button2.setText("取消订单");

                        }
                    }
                }else {
                    tv_title.setText("售仓详情");
                    wt_rest_seats.setText("爽约金");
                    wt_text1.setText("运费");
                }

                break;
            case Constant.WAIT_SURVICE:
                orderType.setText("--待服务");
                if (order.getWho_created()==Constant.PASSENGER){
                    ws_seats_need.setText("提供座位"+order.getSeats()+"个");
                }else {
                    ws_seats_need.setText("座位需求"+order.getSeats()+"个");
                }
                ws_total_price.setText(order.getTotal_money()+"元");
                ws_loss.setText(order.getLoss_money()+"元");
                ArrayList<String> imgList = order.getImgList();
                for (int i = 0; i < imgList.size(); i++) {
                    x.image().bind(ws_cars[i],Common.IMAGE_HOST+imgList.get(i));
                }
                Picasso.with(this).load(Common.IMAGE_HOST+order.getIcon()).error(R.mipmap.morentouxiang).transform(new CircleTransform()).into(ws_icon);
                if (TextUtils.isEmpty(order.getNickname())){
                    ws_nickname.setText("暂无昵称");

                }else {
                    ws_nickname.setText(order.getNickname());

                }

                ws_recent_come.setText("[24h前来过]");
                if (order.getPay_type()==Constant.ALIPAY){
                    ws_pay_type.setText("支付宝支付"+order.getTotal_money()+"元");
                }else if (order.getPay_type()==Constant.RESTPAY){
                    ws_pay_type.setText("余额支付"+order.getTotal_money()+"元");

                }else {
                    ws_pay_type.setText("微信支付"+order.getTotal_money()+"元");
                }
                ws_pay_time.setText(order.getPay_time());
                break;
            case Constant.IN_SURVICE:
                orderType.setText("--服务中");
                if (order.getWho_created()==Constant.PASSENGER){
                    is_seats_need.setText("提供座位"+order.getSeats()+"个");
                }else {
                    is_seats_need.setText("座位需求"+order.getSeats()+"个");
                }
                is_total_price.setText(order.getTotal_money()+"元");
                Picasso.with(this).load(Common.IMAGE_HOST+order.getIcon()).error(R.mipmap.morentouxiang).transform(new CircleTransform()).into(is_icon);
                if (TextUtils.isEmpty(order.getNickname())){
                    is_nickname.setText("暂无昵称");

                }else {
                    is_nickname.setText(order.getNickname());

                }
                is_recent_come.setText("[24h前来过]");
                if (order.getPay_type()==Constant.ALIPAY){
                    is_pay_type.setText("支付宝支付"+order.getTotal_money()+"元");
                }else if (order.getPay_type()==Constant.RESTPAY){
                    is_pay_type.setText("余额支付"+order.getTotal_money()+"元");

                }else {
                    is_pay_type.setText("微信支付"+order.getTotal_money()+"元");
                }
                is_pay_time.setText(order.getPay_time());
                break;
            case Constant.WAIT_FINISH:
                if (order.getWho_created()==Constant.PASSENGER){
                    wf_seats_need.setText("提供座位"+order.getSeats()+"个");
                }else {
                    wf_seats_need.setText("座位需求"+order.getSeats()+"个");
                }
                if (order.getIs_finished()==Constant.PASSENGER_FINISHED_HOST_NO){
                    orderType.setText("--等待我完结");

                }else if (order.getIs_finished()==Constant.HOST_FINISHED_PASSENGER_NO){
                    orderType.setText("--等待对方完结");
                    wf_finish.setVisibility(View.GONE);
                    if (order.getVehicle_type()==Constant.BUS){
                        wf_vehicle_type.setText("[大巴]");
                    }else {
                        wf_vehicle_type.setText("[私家车]");

                    }

                }
                wf_total_price.setText(order.getTotal_money()+"元");
                Picasso.with(this).load(Common.IMAGE_HOST+order.getIcon()).error(R.mipmap.morentouxiang).transform(new CircleTransform()).into(wf_icon);
                if (TextUtils.isEmpty(order.getNickname())){
                    wf_nickname.setText("暂无昵称");

                }else {
                    wf_nickname.setText(order.getNickname());

                }
                wf_recent_come.setText("[24h前来过]");
                if (order.getPay_type()==Constant.ALIPAY){
                    wf_pay_type.setText("支付宝支付"+order.getTotal_money()+"元");
                }else if (order.getPay_type()==Constant.RESTPAY){
                    wf_pay_type.setText("余额支付"+order.getTotal_money()+"元");

                }else {
                    wf_pay_type.setText("微信支付"+order.getTotal_money()+"元");
                }
                wf_pay_time.setText(order.getPay_time());

                break;
            case Constant.FINISHED:
                orderType.setText("--已完结");
                if (order.getWho_created()==Constant.PASSENGER){
                    f_seats_need.setText("提供座位"+order.getSeats()+"个");
                }else {
                    f_seats_need.setText("座位需求"+order.getSeats()+"个");
                }
                f_total_price.setText(order.getTotal_money()+"元");
                Picasso.with(this).load(Common.IMAGE_HOST+order.getIcon()).error(R.mipmap.morentouxiang).transform(new CircleTransform()).into(f_icon);
                if (TextUtils.isEmpty(order.getNickname())){
                    f_nickname.setText("暂无昵称");

                }else {
                    f_nickname.setText(order.getNickname());

                }
                f_recent_come.setText("[24h前来过]");
                if (order.getPay_type()==Constant.ALIPAY){
                    f_pay_type.setText("支付宝支付"+order.getTotal_money()+"元");
                }else if (order.getPay_type()==Constant.RESTPAY){
                    f_pay_type.setText("余额支付"+order.getTotal_money()+"元");

                }else {
                    f_pay_type.setText("微信支付"+order.getTotal_money()+"元");
                }
                f_pay_time.setText(order.getPay_time());
                break;
            case Constant.LOSS:
                orderType.setText("--爽约单");
                outStyle.setTextColor(getResources().getColor(R.color.textcolors));
                orderType.setTextColor(getResources().getColor(R.color.textcolors));
                l_text1.setTextColor(getResources().getColor(R.color.textcolors));
                l_text2.setTextColor(getResources().getColor(R.color.textcolors));
                distance.setTextColor(getResources().getColor(R.color.textcolors));
                l_total_price.setTextColor(getResources().getColor(R.color.textcolors));
                l_loss.setTextColor(getResources().getColor(R.color.textcolors));

                    if (order.getWhy_return().equals("退票")){
                        if (order.getWho_return()==Constant.ME){
                            if (order.getIs_return()==Constant.YES){
                                l_title_info.setText("我退票，我赔付，爽约金"+order.getPayment()+"元将赔付与对方，剩余金额将退化到您的账户，请注意查收");
                                l_whoPay.setImageResource(R.mipmap.wotuipiao);
                            }else {
                                l_title_info.setText("我退票，但我免缴爽约金，不用赔偿给对方");
                                l_whoPay.setImageResource(R.mipmap.wotuipiao);
                            }

                        }else {
                            if (order.getIs_return()==Constant.YES){
                                l_title_info.setText("对方退票，对方赔付，赔付金额"+order.getPayment()+"元，剩余金额"+order.getOwnerPayback()+"元稍后将到您的账户，请查收，感谢您的耐心等待");
                                l_whoPay.setImageResource(R.mipmap.duifangtuipiao);
                            }else {
                                l_title_info.setText("对方退票，但我免缴爽约金，将不会得到对方的赔付");
                                l_whoPay.setImageResource(R.mipmap.duifangtuipiao);
                            }

                        }
                    }else if (order.getWhy_return().equals("改签")){
                        if (order.getWho_return()==Constant.ME){
                            Toast.makeText(context,"loseTarget返回出错",Toast.LENGTH_SHORT).show();
                        }else {
                            if (order.getIs_return()==Constant.YES){
                                l_title_info.setText("对方改签，对方赔付，赔付金额"+order.getPayment()+"元，剩余金额"+order.getOwnerPayback()+"元将退还到您的账户，感谢您的耐心等待");
                                l_whoPay.setImageResource(R.mipmap.duifanggaiqian);
                            }else {
                                l_title_info.setText("对方改签，但我免缴爽约金，将不会得到对方的赔付");
                                l_whoPay.setImageResource(R.mipmap.duifanggaiqian);
                            }


                        }
                    }else if (order.getWhy_return().equals("超时")){
                        if (order.getWho_return()==Constant.ME){
                            if (order.getIs_return()==Constant.YES){
                                l_title_info.setText("对方申诉我超时，我赔付，爽约金"+order.getPayment()+"元将赔付与对方，剩余金额"+order.getOwnerPayback()+"元将退还到您账户");
                                l_whoPay.setImageResource(R.mipmap.wochaoshi);
                            }else {
                                l_title_info.setText("对方申诉我超时，但我免缴爽约金，不用赔偿对方");
                                l_whoPay.setImageResource(R.mipmap.wochaoshi);
                            }

                        }else {
                            if (order.getIs_return()==Constant.YES){
                                l_title_info.setText("对方超时，对方赔付，爽约金"+order.getPayment()+"元将赔付与您，剩余金额"+order.getOwnerPayback()+"元将退还到您的账户，请查收");
                                l_whoPay.setImageResource(R.mipmap.duifangchaoshi);
                            }else {
                                l_title_info.setText("对方超时，但我免缴爽约金，将不会得到对方的赔偿");
                                l_whoPay.setImageResource(R.mipmap.duifangchaoshi);
                            }

                        }
                    }
                break;
            case Constant.EXCEPTION:
                orderType.setText("--订单异常");
                e_loss.setText(order.getLoss_money()+"元");
                e_total_price.setText(order.getTotal_money()+"元");
                e_seats_support.setText("座位需求："+order.getSeats()+"个");
                text_phone.setText("乘客联系方式：");
                if (order.getPay_type()==Constant.ALIPAY){
                    e_pay_type.setText("支付宝支付"+order.getTotal_money()+"元");
                }else if (order.getPay_type()==Constant.RESTPAY){
                    e_pay_type.setText("余额支付"+order.getTotal_money()+"元");
                }else {
                    e_pay_type.setText("微信宝支付"+order.getTotal_money()+"元");
                }
                e_pay_time.setText(order.getPay_time());
                outStyle.setTextColor(getResources().getColor(R.color.textcolors));
                orderType.setTextColor(getResources().getColor(R.color.textcolors));
                e_text1.setTextColor(getResources().getColor(R.color.textcolors));
                e_text2.setTextColor(getResources().getColor(R.color.textcolors));
                distance.setTextColor(getResources().getColor(R.color.textcolors));
                e_total_price.setTextColor(getResources().getColor(R.color.textcolors));
                e_loss.setTextColor(getResources().getColor(R.color.textcolors));

                if (order.getIs_reply()==Constant.YES){
                    e_ll_depart_time.setVisibility(View.VISIBLE);
                    e_ll_go_result.setVisibility(View.GONE);
                }else {
                    e_ll_depart_time.setVisibility(View.GONE);
                    e_ll_go_result.setVisibility(View.VISIBLE);
                }

                break;
        }
    }
    /*
    * 获取订单详情
    * */
    private void httpGetOrderD0etail(int orderStatus) {
        JSONObject object = new JSONObject();

        if (!TextUtils.isEmpty(orderId)){
            object.put("orderId",orderId);
        }else {
            if (orderStatus==0){
                showToast("此为待付款服务，暂无订单详情");
            }else {
                showToast("orderId为空");
            }
            return;
        }

        object.put("orderStatus",orderStatus+"");
        object.put("role","1");
        Log.e("httpGetOrderDetail","orderId="+orderId+" orderStatus="+orderStatus+" role=0");
        httpGet(Common.HOST+Common.ORDER_DETAIL,object, Constant.ORDER_DETAIL);
    }
    /*
    * 获取服务详情
    * */
    private void httpGetServiceDetail(int serviceStatus){
        JSONObject object = new JSONObject();
        object.put("serviceId",serviceId);
        object.put("role","1");
        object.put("serviceStatus",serviceStatus+"");
        httpGet(Common.HOST+Common.SERVICE_DETAIL,object,Constant.SERVICE_DETAIL);

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.button1:
                if (order_type==Constant.WAIT_PAY){
                    //showToast("发布详情—待付款取消订单");
                    cancelOrder("1",order_type+"",order.getOrder_id(),Constant.CANCEL_ORDER);
                }else if (order_type==Constant.WAIT_TAKE){
                    if (order.getIs_timeout()==Constant.YES){
                        //showToast("待接单取消订单");
                        cancelOrder("1",order_type+"",order.getOrder_id(),Constant.CANCEL_ORDER);

                    }else {
                        if (order.getIs_sale_start()==Constant.YES){
                            //showToast("待接单停止售票");
                            JSONObject object = new JSONObject();
                            object.put("serviceId",order.getService_id());
                            object.put("isPermit","0");
                            httpPost(Common.HOST+Common.START_END_SELL,object,Constant.END_SELL);
                        }else {
                            //showToast("待接单开始售票");
                            JSONObject object = new JSONObject();
                            object.put("serviceId",order.getService_id());
                            object.put("isPermit","1");
                            httpPost(Common.HOST+Common.START_END_SELL,object,Constant.START_SELL);

                        }
                    }
                }
                break;
            case R.id.button2:
                if (order_type==Constant.WAIT_PAY){
                    if (tv_title.getText().equals("发布详情")){
                        //showToast("待付款立即发布");
                        if (order.getIs_timeout()==Constant.YES){
                            Intent intent = new Intent(this, ReleaseActivity.class);
                            intent.putExtra("identity",identity);
                            startActivity(intent);
                        }else {
                            Intent intent = new Intent(this, BookPayActivity.class);
                            intent.putExtra("orderCode",order.getOrder_id());
                            intent.putExtra("amount", order.getLoss_money()+"");
                            intent.putExtra("from", Constant.HOST_PUBLISH_PAY);
                            intent.putExtra("id",order.getService_id());
                            intent.putExtra("alipay",Common.HOST_PUBLISH_ALIPAY);
                            intent.putExtra("yivipay",Common.HOST_PUBLISH_RESTPAY);
                            startActivity(intent);
                        }
                    }else {
                        //showToast("待付款立即支付");
                        if (order.getIs_timeout()==Constant.NO){
                            Intent intent = new Intent(this, BookPayActivity.class);
                            intent.putExtra("orderCode",order.getOrder_id());
                            intent.putExtra("amount", order.getLoss_money()+"");
                            intent.putExtra("from", Constant.HOST_ROB_PAY);
                            intent.putExtra("id",order.getService_id());
                            intent.putExtra("alipay",Common.HOST_SEARCH_ALIPAY);
                            intent.putExtra("yivipay",Common.HOST_SEARCH_RESTPAY);
                            startActivity(intent);
                        }

                    }
                }else if (order_type==Constant.WAIT_TAKE){
                    if (order.getIs_timeout()==Constant.YES){
                        //showToast("待接单再次发布");
                        //要退款
                        Intent intent = new Intent(this, ReleaseActivity.class);
                        intent.putExtra("identity",identity);
                        startActivity(intent);
                    }else {
                        if (order.getIs_sale_start()==Constant.YES){
                            //showToast("待接单-售票中-取消订单");
                            cancelOrder("1",order_type+"",order.getOrder_id(),Constant.CANCEL_ORDER);

                        }else {
                            //showToast("待接单-还未开始售票-取消订单");
                            cancelOrder("1",order_type+"",order.getOrder_id(),Constant.CANCEL_ORDER);


                        }
                    }
                 }
                break;
            case R.id.btn_ticket_refund:
                Intent intent = new Intent(this, HostTicketRefundActivity.class);
                intent.putExtra("order",order);
                intent.putExtra("go_type",go_type);
                startActivity(intent);
                break;
            case R.id.btn_start_service:
                JSONObject object = new JSONObject();
                object.put("orderId",order.getOrder_id());
                httpPost(Common.HOST+Common.START_SERVICE,object, Constant.START_SERVICE);
                break;
            case R.id.btn_appeal:
                /*if (order_type==Constant.FINISHED){
                    showToast("已完结申诉");
                }else if (order_type==Constant.IN_SURVICE){
                    showToast("服务中申诉");
                }else if (order_type==Constant.WAIT_FINISH){
                    showToast("待完结申诉");
                }*/
                Intent apIntent = new Intent(this, FWHiteMeShopActivity.class);
                apIntent.putExtra("id","");//被举报人id
                apIntent.putExtra("from",Constant.HOST_APPEAL);//标识
                startActivity(apIntent);
                break;
            case R.id.btn_finish:
                /*if (order_type==Constant.FINISHED){
                    showToast("已完结结束行程");
                }else if (order_type==Constant.IN_SURVICE){
                    showToast("服务中结束行程");
                }else if (order_type==Constant.WAIT_FINISH){
                    showToast("待完结结束行程");
                }*/
                routeFinish();
                break;
            case R.id.btn_cancel_appeal:
                //showToast("订单异常取消申诉");
                cancelAppealDialog();
                break;
            case R.id.tv_wei:
               showToast("暂未开放");
                break;
            case R.id.tv_phone_click:
                if (!TextUtils.isEmpty(phone.getText())){
                    CallPhone.callPhone(this,phone.getText().toString().trim());
                }else {
                    showToast("电话为空");
                }
                break;
            case R.id.ll_go_result:
                jumpToResult();
                break;
        }

    }

    /*
   * 网络请求赋值
   * */
    private void getOrderDetail() {
        switch (order_type){
            case Constant.WAIT_PAY:
                if (!serviceId.equals("")){
                    httpGetServiceDetail(0);
                }else {
                    httpGetOrderDetail(0);
                }
                break;
            case Constant.WAIT_TAKE:
                httpGetServiceDetail(1);
                break;
            case Constant.WAIT_SURVICE:
                httpGetOrderDetail(1);
                break;
            case Constant.IN_SURVICE:
                httpGetOrderDetail(2);
                break;
            case Constant.WAIT_FINISH:
                httpGetOrderDetail(3);
                break;
            case Constant.FINISHED:
                httpGetOrderDetail(4);
                break;
            case Constant.LOSS:
                httpGetOrderDetail(5);
                break;
            case Constant.EXCEPTION:
                httpGetOrderDetail(6);
                break;
        }
    }
    private void httpGetOrderDetail(int orderStatus) {
        JSONObject object = new JSONObject();

        if (!TextUtils.isEmpty(orderId)){
            object.put("orderId",orderId);
        }else {
            if (orderStatus==0){
                showToast("此为待付款服务，暂无订单详情");
            }else {
                showToast("orderId为空");
            }
            return;
        }

        object.put("orderStatus",orderStatus+"");
        object.put("role","0");
        Log.e("httpGetOrderDetail","orderId="+orderId+" orderStatus="+orderStatus+" role=0");
        httpGet(Common.HOST+Common.ORDER_DETAIL,object, Constant.ORDER_DETAIL);
    }
    private void jumpToResult() {
        Intent intent1 = new Intent(this, OrderExceptionResultActivity.class);
        intent1.putExtra("order",order);
        intent1.putExtra("identity",identity);
        startActivity(intent1);
    }

    /*
    * 取消申诉
    * */
    private void cancelAppeal() {
        JSONObject object = new JSONObject();
        object.put("orderId",order.getOrder_id());
        httpPost(Common.HOST+Common.CANCEL_APPEAL,object, Constant.CANCEL_APPEAL);
    }
    /*
    * 行程完结
    * */
    private void routeFinish() {
        JSONObject object = new JSONObject();
        object.put("role",identity+"");
        object.put("orderId",order.getOrder_id());
        httpPost(Common.HOST+Common.ROUTE_FINISH,object, Constant.ROUTE_FINISHED);
    }
    /*
    * 取消订单
    * */
    private void cancelOrder(String type, String serviceStatus, String orderId, String from) {
        JSONObject object = new JSONObject();
        object.put("type",type);
        object.put("serviceStatus",serviceStatus);
        object.put("orderId",orderId);
        httpPost(Common.HOST+Common.CANCEL_ORDER,object,from);
    }

    @Override
    public void onSuccess(String result, String fromWhere) {
        super.onSuccess(result, fromWhere);
        com.alibaba.fastjson.JSONObject obj = JSON.parseObject(result);
        JSONObject data = obj.getJSONObject("data");
        if (fromWhere.equals(Constant.START_SERVICE)){
            showToast("开始服务");
            backResult(Constant.RESULT_START_SERVICE);
        }else if (fromWhere.equals(Constant.CANCEL_ORDER)){
            showToast("取消订单成功");
            backResult(Constant.RESULT_CANCEL_ORDER);
        }else if (fromWhere.equals(Constant.START_SELL)){
            showToast("开始售票成功");
            backResult(Constant.RESULT_START_SELL);
        }else if (fromWhere.equals(Constant.END_SELL)){
            showToast("停止售票成功");
            backResult(Constant.RESULT_END_SELL);
        }else if (fromWhere.equals(Constant.ROUTE_FINISHED)){
            if (order_type==Constant.IN_SURVICE){
                showToast("该订单已进入待完结状态");
                backResult(Constant.RESULT_ROUTE_FINISH_IN_SERVICE);
            }else {
                showToast("该订单已经入已完结状态");
                backResult(Constant.RESULT_ROUTE_FINISH_WAIT_FINISH);
            }
        }else if (fromWhere.equals(Constant.ORDER_DETAIL)){

        }else if (fromWhere.equals(Constant.SERVICE_DETAIL)){

        }
    }

    private void backResult(int result_code) {
        Intent intent = new Intent();
        intent.putExtra("position",position);
        setResult(result_code,intent);
        finish();
    }

    private  void cancelAppealDialog(){
        AlertDialog.Builder builder = null;
        builder = new AlertDialog.Builder(AppManager.getAppManager().currentActivity());
        View view = LayoutInflater.from(AppManager.getAppManager().currentActivity()).inflate(R.layout.dialog_layout, null);
        builder.setView(view);
        TextView cancel = (TextView) view.findViewById(R.id.dialog_cancel);
        TextView sure = (TextView) view.findViewById(R.id.dialog_sure);
        TextView message = (TextView) view.findViewById(R.id.dialog_text);
        sure.setText("确定");
        cancel.setText("取消");
        message.setText("您确定要取消申诉么？");
        final AlertDialog dialog = builder.create();
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cancelAppeal();
                dialog.dismiss();
            }
        });
        dialog.show();
    }
}
